#include"stdio.h"

int main()
{
    int n;
    scanf_s("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int a, b, r;
        scanf_s("%d %d", &a, &b);
        while (b != 0)
        {
            r = b;
            b = a % b;
            a = r;
        }
        printf("%d\n", a);
    }
    return 0;
}